package com.onec.service.customer.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.onec.service.api.dto.request.gateway.BizContent;
import com.onec.service.api.dto.response.BaseResponse;
import com.onec.service.api.enums.ServiceApiEnum;
import com.onec.service.api.enums.error.TradeErrorEnum;
import com.onec.service.api.exception.TradeException;
import com.onec.service.customer.service.online.OnlineBaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author onec
 * @
 * @since 20210107
 */
@Api(value = "merchant", tags = "商户信息公共入口")
@RestController
@RequestMapping(value = "/merchant")
public class MerchantController extends BaseCustomerController {

    /**
     * 创建交易订单.
     *
     * @param
     * @return
     */
    @ApiOperationSupport(order = 10, includeParameters = {"requestData.version", "requestData.bizContent.merchantNo",
            "requestData.bizContent.businessNo"})
    @ApiOperation(value = "/api/online", tags = "商户信息公共入口")
    @ApiParam
    @PostMapping(value = "/api/online")
    public BaseResponse onlineApi(@RequestBody BizContent bizContent) {


        if (!ServiceApiEnum.isInclude(bizContent.getService())) {
            throw new TradeException(TradeErrorEnum.NO_SERVER_ERROR);
        }
        ServiceApiEnum requestMethod = ServiceApiEnum.valueOf(bizContent.getService());
        OnlineBaseService onlineBaseService = applicationContext
                .getBean(requestMethod.name(), OnlineBaseService.class);
        return onlineBaseService.execute(bizContent);
    }
}
